//
//  XKLTabBarItem.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/4/25.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLTabBarItem.h"
#import "XKLPublishView.h"

@interface XKLTabBarItem()

@property (nonatomic,weak)UIButton *publishBut;


@end

@implementation XKLTabBarItem

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIButton *publish=[UIButton buttonWithType:UIButtonTypeCustom];
        [publish setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publish setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
        [publish addTarget:self action:@selector(publishTarget:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:publish];
        self.publishBut=publish;
        
    }
    return self;
}

//点击发布
-(void)publishTarget:(UIButton *)but{
    
    [XKLPublishView show];
    
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    //按钮的宽
    CGFloat width=self.width/(self.items.count+1);
   
    CGFloat height=self.height;
    
    self.publishBut.bounds=CGRectMake(0, 0, width, height);
    self.publishBut.center=CGPointMake(self.width * 0.5, self.height * 0.5);
    
    int index=0;
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            if (index>1) {
                view.frame=CGRectMake((index + 1)* width, 0, width, height);
            }else{
                
                view.frame=CGRectMake(index * width, 0, width, height);
            }
            
            index++;
        }
    }
    
}
@end
